/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelos_programa;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author HUSSEIN
 */
public class eliminarDatos extends javax.swing.JFrame {
    Operaciones_SQL operaciones;
    int dato_1;
    String id;
    /**
     * Creates new form agregarDatos
     */
    public eliminarDatos() {
        initComponents();
        operaciones = new Operaciones_SQL();
        operaciones.conectar();
        setLocationRelativeTo(null);
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        setResizable(false);
    }
    
 
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabel1 = new javax.swing.JLabel();
        btnCancelar = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new java.awt.GridBagLayout());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("ELIMINAR DATOS");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.insets = new java.awt.Insets(26, 0, 10, 0);
        getContentPane().add(jLabel1, gridBagConstraints);

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(42, 54, 35, 38);
        getContentPane().add(btnCancelar, gridBagConstraints);

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButton1.setForeground(new java.awt.Color(153, 0, 0));
        jButton1.setText("Eliminar Todo");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(42, 38, 35, 0);
        getContentPane().add(jButton1, gridBagConstraints);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

            if (JOptionPane.showConfirmDialog(null, "Se eliminaran TODOS LOS DATOS ", "ADVERTENCIA",
            JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                          
            try{

                operaciones.insertar("DELETE FROM DATOS");
                operaciones.insertar("DELETE FROM FREC_TEMP");
                operaciones.insertar("DELETE FROM FRECUENCIA");
                operaciones.insertar("DELETE FROM MUESTRAS");
                operaciones.insertar("DELETE FROM FREC_TEMP2");
                operaciones.insertar("DELETE FROM FRECUENCIA_MUESTRAS");
                
                //actualizar la tabla DATOS
                operaciones.mostrarDatos((DefaultTableModel)ventanaPrincipal.tbDatos.getModel());
                operaciones.mostrarDatos((DefaultTableModel)ventanaPrincipal.tbFrecuencia.getModel());
                operaciones.mostrarDatos((DefaultTableModel)ventanaPrincipal.tbMuestras.getModel());
                operaciones.mostrarDatos((DefaultTableModel)ventanaPrincipal.tbMuestrasFrec.getModel());
                
                ventanaPrincipal.txMedia.setText("");
                ventanaPrincipal.txModa.setText("");
                ventanaPrincipal.txRango.setText("");
                ventanaPrincipal.txDesviacion.setText("");
                ventanaPrincipal.txVarianza.setText("");
                ventanaPrincipal.txRango.setText("");
                ventanaPrincipal.txMinimo.setText("");
                ventanaPrincipal.txMaximo.setText("");
                ventanaPrincipal.txSuma.setText("");
                ventanaPrincipal.txCuenta.setText("");
                ventanaPrincipal.txtAleatorio.setText("");
                ventanaPrincipal.txtDatoAleatorio.setText("");
                ventanaPrincipal.panelGrafico1.removeAll();
                ventanaPrincipal.panelGrafico2.removeAll();
                ventanaPrincipal.panelHistograma.removeAll();
                JOptionPane.showMessageDialog(null,"Se elimino todo con exito");
                ventanaPrincipal.o.clear();
                ventanaPrincipal.p.clear();
            
            }catch(Exception ex){
                JOptionPane.showMessageDialog(null,"Error al eliminar", "Error" ,JOptionPane.ERROR_MESSAGE);
            }
            
            } else {
            // no hacer nada
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(eliminarDatos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(eliminarDatos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(eliminarDatos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(eliminarDatos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new eliminarDatos().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables
}
